/**
 * 验证分页参数的中间件
 */
export const validatePagination = async (ctx: any, next: any) => {
  const page = parseInt(ctx.query.page as string) || 1;
  const limit = parseInt(ctx.query.limit as string) || 10;

  // 确保页码和限制是正数
  if (page < 1) {
    ctx.query.page = '1';
  }

  if (limit < 1) {
    ctx.query.limit = '10';
  }

  // 限制最大每页数量
  if (limit > 100) {
    ctx.query.limit = '100';
  }

  await next();
};